<template>
  <div class="login-page">
    <div class="grid-bg"></div>
    <div class="glow-effect"></div>
    <div class="scan-line"></div>

    <div class="container">
      <!-- 左侧品牌展示区 -->
      <div class="brand-section">
        <div class="particles-background" ref="particles"></div>
        <div class="brand-content">
          <div class="logo">
            <h1>Smartcool</h1>
          </div>
          <div class="slogan">
            智能空调监控与管理平台
          </div>

          <div class="features">
            <div class="feature" v-for="(feature, index) in features" :key="index">
              <div class="feature-icon">
                <i :class="feature.icon"></i>
              </div>
              <div class="feature-text">
                <h3>{{ feature.title }}</h3>
                <p>{{ feature.description }}</p>
              </div>
            </div>
          </div>
        </div>
      </div>

      <!-- 右侧登录表单 -->
      <div class="login-section">
        <div class="login-header">
          <h2>欢迎回来</h2>
          <p>请登录您的账户以继续</p>
        </div>

        <form class="login-form" @submit.prevent="handleLogin">
          <div class="form-group">
            <label for="username">用户名</label>
            <div class="input-with-icon">
              <i class="fas fa-user"></i>
              <input 
                type="text" 
                id="username" 
                v-model="formData.username"
                placeholder="请输入用户名" 
                required
              >
            </div>
          </div>

          <div class="form-group">
            <label for="password">密码</label>
            <div class="input-with-icon">
              <i class="fas fa-lock"></i>
              <input 
                type="password" 
                id="password" 
                v-model="formData.password"
                placeholder="请输入密码" 
                required
              >
            </div>
          </div>

          <div class="remember-forgot">
            <div class="remember">
              <input 
                type="checkbox" 
                id="remember" 
                v-model="formData.rememberMe"
              >
              <label for="remember">记住我</label>
            </div>
            <a href="#" class="forgot-password" @click.prevent="handleForgotPassword">忘记密码?</a>
          </div>

          <button type="submit" class="btn-login" :disabled="isLoggingIn">
            <i class="fas fa-spinner spinner" v-if="isLoggingIn"></i>
            <i class="fas fa-check" v-if="isLoginSuccess"></i>
            <span v-if="!isLoggingIn && !isLoginSuccess">登录系统</span>
            <span v-if="isLoggingIn">登录中...</span>
            <span v-if="isLoginSuccess">登录成功! 跳转中...</span>
          </button>

          <div class="social-login">
            <p>或使用其他方式登录</p>
            <div class="social-icons">
              <a href="#" class="social-icon" @click.prevent="handleSocialLogin('weixin')">
                <i class="fab fa-weixin"></i>
              </a>
              <a href="#" class="social-icon" @click.prevent="handleSocialLogin('qq')">
                <i class="fab fa-qq"></i>
              </a>
              <a href="#" class="social-icon" @click.prevent="handleSocialLogin('microsoft')">
                <i class="fab fa-microsoft"></i>
              </a>
            </div>
          </div>

          <div class="register-link">
            还没有账户? <a href="#" @click.prevent="handleRegister">立即注册</a>
          </div>
        </form>
      </div>
    </div>

    <!-- 通知组件 -->
    <div 
      class="notification" 
      :class="notification.type"
      v-if="notification.show"
      :style="{
        opacity: notification.show ? '1' : '0',
        transform: notification.show ? 'translateY(0)' : 'translateY(-20px)'
      }"
    >
      {{ notification.message }}
    </div>
  </div>
</template>

<script>
export default {
  name: 'SmartcoolLogin',
  data() {
    return {
      // 表单数据
      formData: {
        username: '',
        password: '',
        rememberMe: false
      },
      // 登录状态
      isLoggingIn: false,
      isLoginSuccess: false,
      // 通知信息
      notification: {
        show: false,
        message: '',
        type: ''
      },
      // 功能特点数据
      features: [
        {
          icon: 'fas fa-bolt',
          title: '实时数据监控',
          description: '实时采集空调运行数据，即时报警异常情况'
        },
        {
          icon: 'fas fa-chart-line',
          title: '历史数据分析',
          description: '存储历史运行数据，提供多维度分析和报表'
        },
        {
          icon: 'fas fa-shield-alt',
          title: '安全可靠',
          description: '多重安全防护机制，确保数据安全和设备稳定'
        }
      ]
    };
  },
  mounted() {
    // 初始化粒子背景
    this.createParticles();
    // 添加浮动动画样式
    this.addFloatingAnimation();
    // 创建扫描线
    this.createScanLine();
  },
  methods: {
    // 处理登录
    handleLogin() {
      if (!this.formData.username.trim() || !this.formData.password.trim()) {
        this.showNotification('请输入用户名和密码', 'error');
        return;
      }

      // 模拟登录过程
      this.isLoggingIn = true;
      this.isLoginSuccess = false;

      // 实际应用中这里会调用API进行登录验证
      setTimeout(() => {
        this.isLoginSuccess = true;
        
        setTimeout(() => {
          // 登录成功后跳转（实际应用中使用路由跳转）
          this.showNotification('登录成功！欢迎使用Smartcool智能监控平台', 'success');
          this.isLoggingIn = false;
          this.isLoginSuccess = false;
          // this.$router.push('/dashboard'); // 示例路由跳转
        }, 1500);
      }, 2000);
    },

    // 处理忘记密码
    handleForgotPassword() {
      this.showNotification('忘记密码功能将在这里实现', 'success');
      // 实际应用中这里会跳转到忘记密码页面
      // this.$router.push('/forgot-password');
    },

    // 处理注册
    handleRegister() {
      this.showNotification('注册功能将在这里实现', 'success');
      // 实际应用中这里会跳转到注册页面
      // this.$router.push('/register');
    },

    // 处理社交登录
    handleSocialLogin(type) {
      this.showNotification(`即将使用${this.getSocialName(type)}登录`, 'success');
      // 实际应用中这里会调用对应社交平台的登录API
    },

    // 获取社交平台名称
    getSocialName(type) {
      const names = {
        'weixin': '微信',
        'qq': 'QQ',
        'microsoft': '微软'
      };
      return names[type] || type;
    },

    // 显示通知
    showNotification(message, type) {
      this.notification = {
        show: true,
        message,
        type
      };

      // 3秒后隐藏通知
      setTimeout(() => {
        this.notification.show = false;
      }, 3000);
    },

    // 创建粒子背景
    createParticles() {
      const container = this.$refs.particles;
      const particleCount = 50;

      for (let i = 0; i < particleCount; i++) {
        const particle = document.createElement('div');
        particle.classList.add('particle');

        // 随机大小
        const size = Math.random() * 8 + 2;
        particle.style.width = `${size}px`;
        particle.style.height = `${size}px`;

        // 随机位置
        particle.style.left = `${Math.random() * 100}%`;
        particle.style.top = `${Math.random() * 100}%`;

        // 随机透明度
        const opacity = Math.random() * 0.5 + 0.2;
        particle.style.opacity = opacity;

        // 随机动画
        const animationDuration = Math.random() * 20 + 10;
        particle.style.animation = `float ${animationDuration}s infinite ease-in-out`;

        // 随机颜色变化（蓝色调范围）
        const hue = Math.floor(Math.random() * 40) + 180;
        particle.style.backgroundColor = `hsla(${hue}, 100%, 60%, ${opacity})`;

        container.appendChild(particle);
      }
    },

    // 添加浮动动画样式
    addFloatingAnimation() {
      const style = document.createElement('style');
      style.textContent = `
        @keyframes float {
          0%, 100% {
            transform: translate(0, 0) rotate(0deg);
          }
          25% {
            transform: translate(${Math.random() * 40 - 20}px, ${Math.random() * 40 - 20}px) rotate(${Math.random() * 20 - 10}deg);
          }
          50% {
            transform: translate(${Math.random() * 80 - 40}px, ${Math.random() * 80 - 40}px) rotate(${Math.random() * 40 - 20}deg);
          }
          75% {
            transform: translate(${Math.random() * 40 - 20}px, ${Math.random() * 40 - 20}px) rotate(${Math.random() * 20 - 10}deg);
          }
        }
      `;
      document.head.appendChild(style);
    },

    // 创建扫描线
    createScanLine() {
      // 扫描线样式已在style部分定义
    }
  }
};
</script>

<style scoped>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Exo 2', 'Segoe UI', 'Microsoft YaHei', sans-serif;
}

:root {
  --primary: #0066cc;
  /* 公司主题色 */
  --secondary: #00c1d5;
  --accent: #00d9ff;
  --light: #f8f9fc;
  --dark: #0a1220;
  --gray: #6c757d;
}

.login-page {
  display: flex;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--dark) 0%, #001a33 100%);
  color: white;
  overflow: hidden;
  position: relative;
}

/* 科技感网格背景 */
.grid-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background:
    linear-gradient(rgba(0, 102, 204, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 102, 204, 0.05) 1px, transparent 1px);
  background-size: 30px 30px;
  z-index: -2;
}

/* 科技感光效 */
.glow-effect {
  position: absolute;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at center, rgba(0, 102, 204, 0.15) 0%, transparent 70%);
  z-index: -1;
  animation: glowPulse 8s infinite alternate;
}

.container {
  display: flex;
  width: 100%;
  height: 100vh;
}

/* 左侧品牌展示区 - 增强科技感 */
.brand-section {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 40px;
  z-index: 1;
  overflow: hidden;
  border-right: 1px solid rgba(0, 102, 204, 0.3);
}

.particles-background {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
}

.brand-content {
  max-width: 600px;
  text-align: center;
  z-index: 2;
}

.logo {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 30px;
  position: relative;
}

.logo h1 {
  font-size: 3.5rem;
  font-weight: 700;
  letter-spacing: 2px;
  font-family: 'Orbitron', sans-serif;
  text-transform: uppercase;
  background: linear-gradient(to right, var(--accent), var(--primary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 15px rgba(0, 102, 204, 0.5);
  position: relative;
}

.logo::after {
  content: '';
  position: absolute;
  bottom: -15px;
  left: 50%;
  transform: translateX(-50%);
  width: 120px;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
}

.slogan {
  font-size: 1.8rem;
  margin: 30px 0;
  font-weight: 300;
  line-height: 1.4;
  color: rgba(255, 255, 255, 0.85);
  text-shadow: 0 0 10px rgba(0, 102, 204, 0.5);
}

.features {
  text-align: left;
  max-width: 500px;
  margin: 40px auto;
}

.feature {
  display: flex;
  align-items: flex-start;
  margin-bottom: 25px;
  padding: 20px;
  background: rgba(0, 33, 66, 0.3);
  border-radius: 10px;
  backdrop-filter: blur(5px);
  transition: all 0.4s ease;
  border: 1px solid rgba(0, 102, 204, 0.2);
  position: relative;
  overflow: hidden;
}

.feature::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(0, 102, 204, 0.2), transparent);
  transition: 0.6s;
}

.feature:hover {
  background: rgba(0, 33, 66, 0.5);
  transform: translateY(-5px);
  box-shadow: 0 10px 30px rgba(0, 102, 204, 0.2);
}

.feature:hover::before {
  left: 100%;
}

.feature-icon {
  min-width: 50px;
  height: 50px;
  background: rgba(0, 102, 204, 0.2);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  margin-right: 20px;
  color: var(--accent);
  border: 1px solid var(--primary);
  box-shadow: 0 0 15px rgba(0, 102, 204, 0.3);
}

.feature-text h3 {
  font-size: 1.2rem;
  margin-bottom: 8px;
  color: var(--accent);
  font-weight: 600;
}

.feature-text p {
  font-size: 0.95rem;
  opacity: 0.8;
  line-height: 1.6;
}

/* 右侧登录表单 - 增强科技感 */
.login-section {
  width: 450px;
  background: rgba(10, 25, 47, 0.7);
  backdrop-filter: blur(12px);
  padding: 60px 50px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  box-shadow: 0 0 50px rgba(0, 102, 204, 0.3);
  z-index: 2;
  position: relative;
  overflow-y: auto;
  border-left: 1px solid rgba(0, 102, 204, 0.3);
}

.login-header {
  text-align: center;
  margin-bottom: 40px;
}

.login-header h2 {
  font-size: 2.2rem;
  margin-bottom: 10px;
  background: linear-gradient(to right, var(--accent), var(--primary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  font-family: 'Orbitron', sans-serif;
  letter-spacing: 1px;
}

.login-header p {
  color: rgba(255, 255, 255, 0.7);
  font-size: 1.1rem;
}

.login-form .form-group {
  margin-bottom: 25px;
  position: relative;
}

.login-form label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.95rem;
  color: rgba(255, 255, 255, 0.8);
  font-weight: 500;
}

.input-with-icon {
  position: relative;
}

.input-with-icon i {
  position: absolute;
  left: 15px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--accent);
  font-size: 18px;
  z-index: 2;
}

.login-form input {
  width: 100%;
  padding: 14px 20px 14px 50px;
  border: 1px solid rgba(0, 102, 204, 0.3);
  background: rgba(0, 33, 66, 0.3);
  border-radius: 8px;
  color: white;
  font-size: 16px;
  transition: all 0.3s ease;
  position: relative;
  z-index: 1;
}

.login-form input:focus {
  border-color: var(--accent);
  outline: none;
  background: rgba(0, 33, 66, 0.5);
  box-shadow: 0 0 0 3px rgba(0, 193, 213, 0.3);
}

.remember-forgot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
}

.remember {
  display: flex;
  align-items: center;
}

.remember input {
  width: auto;
  margin-right: 8px;
  accent-color: var(--primary);
}

.forgot-password {
  color: var(--accent);
  text-decoration: none;
  transition: all 0.3s ease;
  font-weight: 500;
  cursor: pointer;
}

.forgot-password:hover {
  text-decoration: underline;
  color: #4ddbff;
}

.btn-login {
  width: 100%;
  padding: 15px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  border: none;
  border-radius: 8px;
  color: white;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  margin-bottom: 25px;
  position: relative;
  overflow: hidden;
  letter-spacing: 1px;
  font-family: 'Orbitron', sans-serif;
  box-shadow: 0 5px 15px rgba(0, 102, 204, 0.4);
}

.btn-login:disabled {
  opacity: 0.8;
  cursor: not-allowed;
}

.btn-login::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
  transition: 0.5s;
}

.btn-login:hover:not(:disabled) {
  transform: translateY(-3px);
  box-shadow: 0 10px 25px rgba(0, 102, 204, 0.6);
}

.btn-login:hover:not(:disabled)::before {
  left: 100%;
}

.social-login {
  text-align: center;
  margin: 25px 0;
  position: relative;
}

.social-login::before,
.social-login::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 30%;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--primary), transparent);
}

.social-login::before {
  left: 0;
}

.social-login::after {
  right: 0;
}

.social-login p {
  margin-bottom: 15px;
  color: rgba(255, 255, 255, 0.7);
}

.social-icons {
  display: flex;
  justify-content: center;
  gap: 15px;
}

.social-icon {
  width: 45px;
  height: 45px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 33, 66, 0.3);
  color: white;
  font-size: 18px;
  transition: all 0.3s ease;
  border: 1px solid rgba(0, 102, 204, 0.3);
  cursor: pointer;
}

.social-icon:hover {
  transform: translateY(-5px);
  background: var(--primary);
  box-shadow: 0 5px 15px rgba(0, 102, 204, 0.4);
}

.register-link {
  text-align: center;
  margin-top: 20px;
  color: rgba(255, 255, 255, 0.7);
}

.register-link a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  margin-left: 5px;
  transition: all 0.3s ease;
  cursor: pointer;
}

.register-link a:hover {
  text-decoration: underline;
  color: #4ddbff;
}

/* 粒子样式 */
.particle {
  position: absolute;
  border-radius: 50%;
  background: rgba(0, 102, 204, 0.5);
  z-index: -1;
}

/* 扫描线 */
.scan-line {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: scan 4s linear infinite;
  opacity: 0.7;
  z-index: 10;
}

/* 通知样式 */
.notification {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 15px 25px;
  border-radius: 8px;
  color: white;
  font-weight: 500;
  box-shadow: 0 5px 15px rgba(0,0,0,0.3);
  z-index: 1000;
  transition: all 0.3s ease;
}

.notification.success {
  background: linear-gradient(135deg, #00c853, #009624);
  border-left: 4px solid #00e676;
}

.notification.error {
  background: linear-gradient(135deg, #ff5252, #c50e29);
  border-left: 4px solid #ff5252;
}

/* 动画效果 */
@keyframes glowPulse {
  0% {
    opacity: 0.3;
  }
  100% {
    opacity: 0.7;
  }
}

@keyframes scan {
  0% {
    top: 0;
  }
  100% {
    top: 100%;
  }
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.spinner {
  animation: spin 1s linear infinite;
  display: inline-block;
  margin-right: 10px;
}

/* 响应式设计 */
@media (max-width: 992px) {
  .container {
    flex-direction: column;
    height: auto;
  }

  .brand-section {
    padding: 30px 20px;
    flex: none;
    height: auto;
    border-right: none;
    border-bottom: 1px solid rgba(0, 102, 204, 0.3);
  }

  .login-section {
    width: 100%;
    padding: 40px 30px;
    border-radius: 0;
    border-left: none;
  }

  .logo h1 {
    font-size: 2.8rem;
  }

  .slogan {
    font-size: 1.5rem;
  }

  .features {
    margin: 30px auto;
  }
}

@media (max-width: 576px) {
  .remember-forgot {
    flex-direction: column;
    align-items: flex-start;
    gap: 15px;
  }

  .feature {
    padding: 15px;
  }

  .login-section {
    padding: 35px 20px;
  }

  .login-header h2 {
    font-size: 1.8rem;
  }

  .social-login::before,
  .social-login::after {
    width: 25%;
  }
}
</style>